//app.js
App({
    data: {
        baseUrl: 'http://www.ttlshop.cn'
    },

    globalData: {
        userInfo: null,
        openid: null

    },
    onLaunch: function() {
        //调用API从本地缓存中获取数据
        var logs = wx.getStorageSync('logs') || []
        logs.unshift(Date.now())
        wx.setStorageSync('logs', logs);
        this.getUserInfo();

    },
    onShow: function() {

    },
    getUserInfo: function(cb) {
        var that = this;
        if (this.globalData.userInfo) {
            typeof cb == "function" && cb(this.globalData.userInfo)
        } else {
            //调用登录接口
            wx.login({
                success: function(res1) {
                    console.log(res1)
                    wx.request({
                        url: that.data.baseUrl + '/AibraUsb/userInfo/getSessionKeyOropenid.do?code=' + res1.code,
                        success: function(res) {
                            console.log('app.js openid', res.data.openid)
                            that.globalData.openid = res.data.openid
                        }
                    })
                    wx.getUserInfo({
                        success: function(res) {
                            that.globalData.userInfo = res.userInfo
                            typeof cb == "function" && cb(that.globalData.userInfo)
                        }
                    })
                }
            })
        }
    },

})